|
|
|
|
|
|
|
Running this query in Access prompts you for the Letter parameter and then displays the matching records. To run this Access query from VB code, you can use a Command object, as follows: |
|
|
|
|
|
|
|
|
Dim cmd As New ADODB.Command
Dim parmTemp As ADODB.Parameter
Set cmd.ActiveConnection = cn
cmd.CommandText = "LetterLookup"
cmd.CommandType = adCmdStoredProc
Set parmTemp = cmd.CreateParameter("Letter", adChar, adParamInput, 1)
cmd.Parameters.Append parmTemp
cmd("Letter") = "Q"
Set rs = cmd.Execute |
|
|
|
|
|
|
|
|
To use the Command object, you have to decide on the type of command it is (these types are listed earlier in the chapter) and specify the actual command. If any parameters are required, you can add them to the Parameters collection of the object. After you set up the Command object, simply call the Execute method to perform the command. |
|
|
|
|
|
|
|
|
If you have worked with DAO in the past, then you will find that ADO has new features that allow you to manipulate recordsets in ways that were never before possible. One new feature is the ability to create disconnected recordsets. This term means that you can have a recordset in memory that is independent of a database connection. While disconnected, the recordset acts as a standalone object, with all the usual methods and properties. What is even more amazing is that you can later reconnect the recordset and commit any changes made while the recordset was disconnected. As you will see shortly, disconnected recordsets are most useful on the Internet, because you do not always have a continuous connection to the database. In the following sections, you see how to handle these recordsets. |
|
|
|
|
|
|
|
|
Creating a Disconnected Recordset |
|
|
|
|
|
|
|
|
The key to creating a disconnected recordset is setting the CursorLocation property. It has two settings: adUseClient and adUseServer. To create a disconnected recordset (or client-side cursor), perform the following steps: |
|
|
|
|
|
|
|
|
1. Set the CursorLocation property to adUseClient. |
|
|
|
|
|
|
|
|
2. Populate the Recordset object. |
|
|
|
|
|
|
|
|
3. Set the ActiveConnection property to Nothing. |
|
|
|
|
|
|
|
|
Recall the example from Listing 28.2, which displayed publisher information in a list box. You can easily change it to use a disconnected recordset by changing the Form_Load event procedure, as follows: |
|
|
|
|
|